export class ApiResponse<T = any> {
  code: number;
  message: string;
  data?: T;
  timestamp: string;

  constructor(code: number, message: string, data?: T) {
    this.code = code;
    this.message = message;
    this.data = data;
    this.timestamp = new Date().toISOString();
  }

  static success<T>(data?: T, message: string = '操作成功'): ApiResponse<T> {
    return new ApiResponse(200, message, data);
  }

  static error(message: string = '操作失败', code: number = 500): ApiResponse {
    return new ApiResponse(code, message);
  }

  static unauthorized(message: string = '登录失效/未登录'): ApiResponse {
    return new ApiResponse(401, message);
  }

  static badRequest(message: string = '请求参数错误'): ApiResponse {
    return new ApiResponse(400, message);
  }
}
